/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.effect;

import org.meanzoft.m3d.scene.Renderable;
import org.meanzoft.m3d.scene.SceneNode;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import static org.lwjgl.opengl.GL11.*;

/**
 *
 * @author Meanz
 */
public class Fog {

    private int filter;
    private int[] fogMode = {GL_EXP, GL_EXP2, GL_LINEAR};
    public int fogFilter = 0;
    private float[] fogColor = {0.5f, 0.5f, 0.5f, 1.0f};
    private boolean enabled;

    public void enable() {
        update();
        glEnable(GL_FOG);
        enabled = true;
    }

    public void disable() {
        glDisable(GL_FOG);
        enabled = false;
    }

    public void update() {
        ByteBuffer temp = ByteBuffer.allocateDirect(16);
        temp.order(ByteOrder.nativeOrder());
        glFogi(GL_FOG_MODE, fogMode[fogFilter]);                  // Fog Mode
        temp.asFloatBuffer().put(fogColor).flip();
        glFog(GL_FOG_COLOR, temp.asFloatBuffer());                // Set Fog Color
        glFogf(GL_FOG_DENSITY, 0.35f);                            // How Dense Will The Fog Be
        glHint(GL_FOG_HINT, GL_DONT_CARE);                   // Fog Hint Value
        glFogf(GL_FOG_START, 3.0f);                               // Fog Start Depth
        glFogf(GL_FOG_END, 10.0f);                                 // Fog End Depth
    }

    public boolean isEnabled() {
        return enabled;
    }
}
